{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h4 class="mb-0">提交论文信息</h4>
                </div>
                <div class="card-body">
                    <form method="POST" enctype="multipart/form-data">
                        {{ form.hidden_tag() }}
                        <div class="mb-3">
                            {{ form.title.label(class="form-label") }}
                            {{ form.title(class="form-control") }}
                            {% for error in form.title.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                        </div>
                        <div class="mb-3">
                            {{ form.description.label(class="form-label") }}
                            {{ form.description(class="form-control", rows="4") }}
                            {% for error in form.description.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                        </div>
                        <div class="mb-3">
                            {{ form.programming_language.label(class="form-label") }}
                            {{ form.programming_language(class="form-select") }}
                            {% for error in form.programming_language.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                        </div>
                        <div class="mb-3">
                            {{ form.thesis_type.label(class="form-label") }}
                            {{ form.thesis_type(class="form-select") }}
                            {% for error in form.thesis_type.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                            <small class="form-text text-muted">
                                <ul class="mt-2">
                                    <li>毕业设计：包含完整源代码、部署文档和技术指导</li>
                                    <li>毕业论文：包含论文撰写指导和修改建议.</li>
                                    <li>全套服务：包含毕业设计和初始论文+后期指导的所有服务</li>
                                    <li>备注：无法保证提供的论文一定能通过，毕竟16级学长亲身经历，这玩意不到最后几天能改10次，而且每次自查知网费用好像是20-30元</li>
                                </ul>
                            </small>
                        </div>
                        <div class="mb-3">
                            {{ form.price.label(class="form-label") }}
                            <div class="input-group">
                                {{ form.price(class="form-control", type="number", min="0", max="1000", step="100", value="0") }}
                                <span class="input-group-text">元</span>
                            </div>
                            {% for error in form.price.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                            <small class="form-text text-muted">如需额外功能，可以追加预算</small>
                        </div>
                        <div class="mb-3">
                            {{ form.contact_info.label(class="form-label") }}
                            {{ form.contact_info(class="form-control") }}
                            {% for error in form.contact_info.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                        </div>
                        <div class="mb-3">
                            {{ form.deadline.label(class="form-label") }}
                            {{ form.deadline(class="form-control", type="date", min=today.strftime('%Y-%m-%d')) }}
                            {% for error in form.deadline.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                        </div>
                        <div class="mb-3 form-check">
                            {{ form.need_environment(class="form-check-input") }}
                            {{ form.need_environment.label(class="form-check-label") }}
                        </div>
                        <div class="mb-3">
                            {{ form.proposal_file.label(class="form-label") }}
                            {{ form.proposal_file(class="form-control") }}
                            {% for error in form.proposal_file.errors %}
                            <span class="text-danger">{{ error }}</span>
                            {% endfor %}
                            <small class="form-text text-muted">
                                支持的文件格式：PDF、Word文档（doc/docx）<br>
                                开题报告为选填项，您可以稍后再上传
                            </small>
                        </div>
                        <div class="d-grid">
                            {{ form.submit(class="btn btn-primary") }}
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    const typeSelect = document.getElementById('thesis_type');
    const priceInput = document.querySelector('input[type="number"]');
    const envCheckbox = document.getElementById('need_environment');
    
    // 处理额外预算输入
    priceInput.addEventListener('change', function(e) {
        let value = parseInt(this.value) || 0;
        if (value < 0) value = 0;
        if (value > 1000) value = 1000;
        // 确保值是100的倍数
        value = Math.round(value / 100) * 100;
        this.value = value;
        updateTotalPrice();
    });

    function updateTotalPrice() {
        let basePrice = 0;
        // 如果没有选择类型，价格为0
        if (typeSelect.value) {
            switch(typeSelect.value) {
                case 'design':
                    basePrice = 700;
                    break;
                case 'thesis':
                    basePrice = 500;
                    break;
                case 'full':
                    basePrice = 1000;
                    break;
            }
        }
        
        let extraPrice = parseInt(priceInput.value) || 0;
        let envPrice = envCheckbox.checked ? 100 : 0;
        
        let totalPrice = basePrice + extraPrice + envPrice;
        
        // 显示总价
        document.getElementById('total-price').textContent = totalPrice;
    }
    
    typeSelect.addEventListener('change', updateTotalPrice);
    envCheckbox.addEventListener('change', updateTotalPrice);
    
    // 初始化总价显示
    updateTotalPrice();
});
</script>
{% endblock %}

<div class="alert alert-info mb-3">
    <h5 class="mb-0">
        总价：¥<span id="total-price">0</span>
        <small class="text-muted">（基础价格 + 额外预算 + 环境配置）</small>
    </h5>
</div>

{% endblock %} 